<div class="row">
	<div class="col-lg-12">
		<h1 class="site-h1" style="background-color:#FFFFFF;">
			帖子列表<#if topicadminList??>（${topicadminList.totalElements!''}）</#if>
			<span style="float:right;">
				<button class="layui-btn layui-btn-small green" href="/topic/adminadd.html" data-toggle="ajax"  data-href-index="/topic/adminindex" data-width="80%" data-height="95%" data-title="创建新帖子">
					创建新帖子
				</button>
			</span>
			<span style="float:right;margin-right: 10px;">
				<button class="layui-btn layui-btn-small ukefu-bg-color-pink2" onclick="deleteAll()">
					全部删除
				</button>
			</span>
		</h1>
		<div class="row" style="padding:5px;">
			<div class="col-lg-12">
				<table class="layui-table" lay-skin="line">
				  <colgroup>
				  		<col width="15%">
						<col width="30%">
						<col width="10%">
						<col width="10%">
						<col width="10%">
						<col width="10%">
						<col width="20%">
					<col>
				  </colgroup>
				  <thead>
					<tr>
					  <th><input  type="checkbox" onclick="checkAll(this)">全选</th>
					  <th>标题</th>
					  <th>板块</th>
					  <th>分类</th>
					  <th>发布人</th>
					  <th>更新时间</th>
					  <th style="white-space:nowrap;" nowrap="nowrap">操作</th>
					</tr> 
				  </thead>
				  <tbody>
					<#if topicadminList?? && topicadminList??>
					<#list topicadminList.content as list>
					<tr>
					  <td><input onclick="IsAllcheck()" class="check${list.id!''}" type="checkbox" value="${list.id!''}"></td>
					  <td>${list.title!''}</td>
					  <td>${list.blockparent.blockname!''}</td>
					  <td>${list.block.blockname!''}</td>
					  <td>${list.username!''}</td>
					  <td>${list.updatetime?string('yyyy-MM-dd')} </td>
					  <td style="white-space:nowrap;" nowrap="nowrap">
					  		<a href="/topic/adminedit.html?id=${list.id!''}" data-toggle="ajax"  data-href-index="/topic/adminindex"  data-width="80%" data-height="95%" data-title="编辑">
					  			<i class="layui-icon">&#xe642;</i>
					  			编辑
					  		</a>
					  		<a href="/topic/admindelete.html?id=${list.id!''}" style="margin-left:10px;" data-toggle="tip" data-title="请确认是否删除该帖子？">
					  			<i class="layui-icon" style="color:red;">&#x1006;</i>
					  			删除
					  		</a>
					  </td>
					</tr>
					</#list>
					</#if>
				  </tbody>
				</table>
			</div> 	   
		</div>
		<div class="row" style="padding:5px;">
			<div class="col-lg-12" id="page" style="text-align:center;"></div>
		</div>
	</div>	
</div>
<script>
	layui.use(['laypage', 'layer'], function(){
	  var laypage = layui.laypage
	  ,layer = layui.layer;
	  
	laypage({
			cont: 'page'
			,pages: <#if topicadminList??>${topicadminList.totalPages}<#else>0</#if> //总页数
			,curr:<#if topicadminList??>${topicadminList.number+1}<#else>0</#if>
			,groups: 5 //连续显示分页数
			,jump:function(data , first){
				if(!first){
					location.href = "/topic/adminindex.html?p="+data.curr ;
				}
			}
	   });
	});
	function checkAll(input){
		if(input.checked){
			$("table tbody td input[type=checkbox]").prop("checked",true);
		}else{
			$("table tbody td input[type=checkbox]").prop("checked",false);
		}
	}
	
	function IsAllcheck(){
		if($("table tbody td input:checked").length == $("table tbody td input[type=checkbox]").length){
			$("table thead th input[type=checkbox]").prop("checked",true)
		}else{
			$("table thead th input[type=checkbox]").prop("checked",false)
		}
	}
	
	function deleteAll(){
		var topicLists =  [];
		$("table tbody td input:checked").each(function(item,index){
			topicLists.push(index.value);
		})
		if(topicLists.length > 0){
			$.ajax({
				type: "POST",
				url: "/topic/admindeleteList.html" ,
				data: {topicLists: topicLists.join(",")},
				async: false,
				success: function(data) {
					if(data == "success"){
			       		 window.location.href = "/topic/adminindex.html";
			       	 }else{
			       		layer.msg('批量删除失败，请重新尝试!', {icon: 1}); 
			       	 }
				}
				
			});
		}else{
			layer.msg('请选中帖子!', {icon: 1}); 
		}
		
	}
</script>